#include "SBFlee.h"
#include "AIAgent.h"

SBFlee::SBFlee( AIAgent* __restrict agent , GameObject* __restrict objectToFleeFrom, float minDist) : Behaviour(agent), m_minDist(minDist)
{
	m_debugDrawColour = Vec3f(0.6f, 0.4f, 0);
	m_pTarget = objectToFleeFrom;
	m_minDistSqr = m_minDist*m_minDist;
}

Vec3f SBFlee::Update()
{

	Vec3f difference = m_pAgent->GetPos() - m_pTarget->GetPos();
	float distSqr = difference.LengthSqr();
	if(distSqr < m_minDistSqr)
	{
		if(distSqr > 0)
		{
			return (difference.TruncateReturn(m_pAgent->GetMaxForce()));
		}
		else
		{
			return Vec3f();
		}
	}
	else
	{
		return Vec3f();
	}
}